<template>
  <div class="role-list">
    <!-- <el-button type="primary" @click="addRole">添加</el-button> -->
    <el-table :data="roleList" border style="width: 100%">
      <el-table-column label="编号">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="角色名称" prop="name"> </el-table-column>
      <!-- <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="handleEdit(scope.row)"
            >编辑</el-button
          >
          <el-button type="danger" size="small" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <!-- <el-dialog
      :title="type == '1' ? '添加' : '编辑'"
      :visible.sync="dialogEdit"
      width="30%"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
      >
        <el-form-item label="角色" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogEdit = false;resetForm('ruleForm')">取 消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
      </span>
    </el-dialog> -->
    <el-pagination
      @size-change="sizeChange"
      @current-change="currentChange"
      :current-page="pageNo"
      :page-size="pageSize"
      layout="total, prev, pager, next"
      :total="total"
      background
    ></el-pagination>
  </div>
</template>

<script>
export default {
  name: "RoleList",
  data() {
    return {
      sname: "",
      pageNo: 1,
      pageSize: 10,
      total: 3,
      roleList: [
        { id: "1", name: "管理员" },
        { id: "2", name: "店长" },
        { id: "3", name: "店员" }
      ],
      type: "1", //1添加 2编辑
      dialogEdit: false,
      ruleForm: {
        name: ""
      },
      rules: {
        name: [{ required: true, message: "请输入角色名称", trigger: "blur" }]
      }
    };
  },
  methods: {
    sizeChange() {},
    currentChange() {},
    goPage(path) {
      this.$router.push(path);
    },
    addRole() {
      this.dialogEdit = true;
      this.type = "1";
      
      this.$nextTick(() => {
        this.$refs["ruleForm"].clearValidate();
      });
      this.resetForm("ruleForm");
    },
    handleEdit(row) {
      this.dialogEdit = true;
      this.type = "2";
      this.ruleForm.name = row.name;
    },
    handleDelete(row) {
      this.$confirm("确定要删除此角色吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {})
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$nextTick(() => {
        this.$refs[formName].resetFields();
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.role-list {
  padding: 40px;
  .el-button {
    margin-bottom: 20px;
  }
}
</style>
